package com.briup.smartcity_group7.exception;

import com.briup.smartcity_group7.util.Result;
import com.briup.smartcity_group7.util.ResultUtil;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author: lenovo
 * @Date: 2023/12/30/12:48
 * 使用AOP实现统一异常信息--全局异常处理操作
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    public Result handleException(Exception ex){
        ex.printStackTrace();//打印
        //可以处理controller方法和拦截器方法抛出的异常
        if(ex instanceof ServiceException){
            return ResultUtil.error(ex.getMessage());
        }
        return ResultUtil.error("程序内部错误");
    }
}